<?php

namespace app\model;
use think\Model;

class Order extends Model
{
    public function buyOne($data){
        $res = Order::create($data);
        return $res;
    }

    public function getAll($user_id){
        $res = Order::where('user_id',$user_id)->paginate(10);
        return $res;
    }

    public function getStatusAttr($v){
        $status=[
            1=>'等待发货',
            0=>'已收货',
            2=>'发货中'
        ];
        return $status[$v];
    }

    //取消商品后删除订单
    public function cancel($id){
        $res = Order::where('id',$id)->delete();
        return $res;
    }

    //删除订单（假删除）
    public function hiddenOrder($id){
        return Order::where('id',$id)->inc('is_delete',1)->update();
    }

    //恢复订单（真恢复）
    public function recOrder($id){
        return Order::where('id',$id)->dec('is_delete',1)->update();
    }

    public function delOrder($id){
        return Order::where('id',$id)->delete();
    }

}